package org.thomias.swtmultithread.startstop;

import org.thomias.loggertest.YT;

public class BarThread extends Thread {
	private Application app;

	public BarThread(Application application) {
		this.app = application;
	}

	@Override
	public void run() {
		while (app.i < 100) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				return;
			}
			app.i++;
			YT.debug("i=" + app.i);
		}
		conclude();
	}

	private void conclude() {
		app.getShell().getDisplay().asyncExec(new Runnable() {
			public void run() {
				if (app.i == 100) {
					app.btn.setText("Finished");
					app.btn.setEnabled(false);
					app.updateProgressBar();
					app.updateLabel();
					app.updateTime();
					app.m.stop();
				}
			}
		});
	}

}
